package com.somlsis.activity

import android.Manifest
import android.content.Intent
import android.view.LayoutInflater
import android.widget.Toast
import com.base.BaseActivity
import com.permissionx.guolindev.PermissionX
import com.somlsis.databinding.ActivityWelcomeBinding
import com.widget.WheelView


class WelcomeActivity : BaseActivity<ActivityWelcomeBinding>() {
    override fun getViewBinding(): ActivityWelcomeBinding {
        return ActivityWelcomeBinding.inflate(LayoutInflater.from(this))
    }

    override fun createView() {
        val requestList = ArrayList<String>()
        requestList.add(Manifest.permission.BLUETOOTH)
        requestList.add(Manifest.permission.BLUETOOTH_ADMIN)
        requestList.add(Manifest.permission.ACCESS_COARSE_LOCATION)
        requestList.add(Manifest.permission.ACCESS_FINE_LOCATION)
        requestList.add(Manifest.permission.WRITE_EXTERNAL_STORAGE)
        requestList.add(Manifest.permission.READ_EXTERNAL_STORAGE)
        requestList.add(Manifest.permission.CAMERA)

        PermissionX.init(this)
            .permissions(requestList)
            .onExplainRequestReason { scope, deniedList ->
                val message = "PermissionX需要您同意以下权限才能正常使用"
                scope.showRequestReasonDialog(deniedList, message, "Allow", "Deny")
            }
            .request { allGranted, _, deniedList ->
                if (allGranted) {
                    Toast.makeText(this, "所有申请的权限都已通过", Toast.LENGTH_SHORT).show()
                } else {
                    Toast.makeText(this, "您拒绝了如下权限：$deniedList", Toast.LENGTH_SHORT).show()
                }
            }

        binding.running.setOnClickListener {
            deviceCenter.createDevice()
            val user = dataCenter.getUser()
            if (user != null) {
                startActivity(Intent(this, HomeActivity::class.java))

            } else {
                startActivity(Intent(this, LoginActivity::class.java))
            }
            finish()
        }
        binding.wheel.setOnWheelItemSelectedListener(object :
            WheelView.OnWheelItemSelectedListener {
            override fun onWheelItemChanged(wheelView: WheelView?, position: Int) {
                binding.test.text=position.toString()
            }

            override fun onWheelItemSelected(wheelView: WheelView?, position: Int) {

            }

        })
    }
}